package org.pupil.common;

import org.pupil.socket.codec.RpcResponse;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @Description: 请求管理
 * @Author: pupil
 * @Date: 2024/07/09 下午 3:08
 */
public class RpcRequestHolder {

    // 请求id
    private static final  AtomicLong REQUEST_ID_GEN = new AtomicLong(0);

    // 绑定请求
    public static final Map<Long,RpcFuture<RpcResponse>> REQUEST_MAP = new ConcurrentHashMap<>();

    // 获取请求id
    public static Long getRequestId(){
        if (REQUEST_ID_GEN.longValue() == Long.MAX_VALUE){
            REQUEST_ID_GEN.set(0); // 累加达到最大值，置零
        }
        return REQUEST_ID_GEN.incrementAndGet();
    }
}
